package poli.tidia.mobile;

import java.util.List;

import poli.tidia.mobile.model.Forum;
import poli.tidia.mobile.model.Site;
import poli.tidia.mobile.model.Topic;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class TopicListActivity extends ListActivity {

	@Override
	public void onCreate(Bundle saved) {
		super.onCreate(saved);

		Bundle bundle = getIntent().getExtras();

		if (bundle != null) {
			Forum selectedSite = (Forum) bundle.getSerializable("selectedForum");
			List<Topic> topics = selectedSite.getTopics();

			getListView().setBackgroundColor(Color.WHITE);

			TopicArrayAdapter adapter = new TopicArrayAdapter(this,
					topics);
			setListAdapter(adapter);
		}
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		Bundle b = getIntent().getExtras();
		if (b != null) {
			Site selectedSite = (Site) b.getSerializable("selectedSite");

			Intent selectedResourceIntent = new Intent(TopicListActivity.this,
					ThreadListActivity.class);
			selectedResourceIntent.putExtra("selectedSite", selectedSite);
			selectedResourceIntent.putExtra("selectedTopic", (Topic) getListAdapter().getItem(position));

			startActivity(selectedResourceIntent);
		}
	}
	
}
